package com.kgc.basicprovider.controller;

import com.kgc.basic.pojo.Good;
import com.kgc.basic.remote.GoodRemote;
import com.kgc.basic.util.ResponseMsg;
import com.kgc.basicprovider.service.GoodService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
public class GoodController implements GoodRemote {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private GoodService goodService;

    @Override
    public ResponseMsg getGoodPage(@RequestBody Map<String, Object> map) {
        logger.info("GoodController getGoodPage map:"+map);
        ResponseMsg responseMsg = goodService.getGoodPage(map);
        logger.debug("GoodController getGoodPage responseMsg:"+responseMsg+"params:"+map);
        return responseMsg;
    }

    @Override
    public ResponseMsg getAllGood(@RequestBody Map<String, Object> map) {
        logger.info("GoodController getGoodPage map:"+map);
        ResponseMsg responseMsg = goodService.getAllGood(map);
        logger.debug("GoodController getGoodPage responseMsg:"+responseMsg+"params:"+map);
        return responseMsg;
    }

    @Override
    public ResponseMsg addGood(@RequestBody Good good) {
        logger.info("GoodController addGood good:{}", good);
        ResponseMsg responseMsg = goodService.addGood(good);
        logger.debug("GoodController addGood responseMsg:{}", responseMsg+",good:"+good);
        return responseMsg;
    }

    @Override
    public ResponseMsg updateGood(@RequestBody Good good) {
        logger.info("GoodController updateGood good:{}", good);
        ResponseMsg responseMsg = goodService.updateGood(good);
        logger.debug("GoodController updateGood responseMsg:{}", responseMsg+",good:"+good);
        return responseMsg;
    }

    @Override
    public ResponseMsg delGood(@RequestParam("id") String id) {
        logger.info("GoodController delGood good:{}", id);
        ResponseMsg responseMsg = goodService.delGood(id);
        logger.debug("GoodController delGood responseMsg:{}", responseMsg+",id:"+id);
        return responseMsg;
    }

    @Override
    public ResponseMsg getGoodById(@RequestParam("id") String id) {
        logger.info("GoodController getGoodBtId id:{}", id);
        ResponseMsg responseMsg = goodService.getGoodById(id);
        logger.debug("GoodController getGoodBtId responseMsg:{}", responseMsg+",id:"+id);
        return responseMsg;
    }

    @Override
    public ResponseMsg getGoodList(@RequestBody List<String> idList) {
        logger.info("GoodController getGoodBtId idList:{}", idList);
        ResponseMsg responseMsg = goodService.getGoodList(idList);
        logger.debug("goodService getGoodList responseMsg:{}", responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg changeStock(Map<String, Object> map) {
        logger.info("GoodController changeStock map:"+map);
        ResponseMsg responseMsg = goodService.changeStock(map);
        logger.debug("GoodController changeStock responseMsg:{}", responseMsg);
        return responseMsg;
    }
}
